package com.ytjj.qmyx.supplychain.service;

import com.ytjj.qmyx.supplychain.common.enums.BankerMessageStatusEnum;
import com.ytjj.qmyx.supplychain.mapper.BankerMessageMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.YxBanker;
import com.ytjj.qmyx.supplychain.mapper.entity.YxBankerMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 
 * 
 * @Version: 1.0
 */
@Service
public class BankerMessageService {
    @Resource
    private BankerMessageMapper bankerMessageMapper;
    @Autowired
    private BankerService bankerService;

    public List<YxBankerMessage> waitLookList() {
        YxBanker userInfo = bankerService.getUserInfo();
        Example example = new Example(YxBankerMessage.class);
        example.createCriteria().andEqualTo("bankerId", userInfo.getId()).andEqualTo("status", BankerMessageStatusEnum.NO_READ.getCode());
        example.orderBy("createTime").desc();
        List<YxBankerMessage> messageList = bankerMessageMapper.selectByExample(example);
        return messageList;
    }

    public List<YxBankerMessage> outLookList() {
        YxBanker userInfo = bankerService.getUserInfo();
        Example example = new Example(YxBankerMessage.class);
        example.createCriteria().andEqualTo("bankerId", userInfo.getId()).andEqualTo("status", BankerMessageStatusEnum.READ.getCode());
        example.orderBy("createTime").desc();
        List<YxBankerMessage> messageList = bankerMessageMapper.selectByExample(example);
        return messageList;
    }

    public Integer updateStatus(Integer id) {
        YxBankerMessage bean = new YxBankerMessage();
        bean.setId(id);
        bean.setSeeTime(new Date());
        bean.setStatus(BankerMessageStatusEnum.READ.getCode());
        return bankerMessageMapper.updateByPrimaryKeySelective(bean);
    }

    public YxBankerMessage getRemarks(Integer id) {
        return bankerMessageMapper.selectByPrimaryKey(id);
    }
}
